import 'package:shop/common/AppStorge.dart';
import 'package:shop/common/shop_material.dart';
import 'package:shop/service/MemberService.dart';
import 'package:shop/utils/MyToast.dart';

import 'LoginIndex.dart';

class QuickLogin extends StatefulWidget {
  QuickLogin({Key key}) : super(key: key);
  @override
  _QuickLoginState createState() => _QuickLoginState();
}

class _QuickLoginState extends State<QuickLogin> {
  Map loginMap;

  @override
  void initState() {
    super.initState();
    loginMap = MyStorge.login;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading:
            IconButton(icon: Icon(Icons.close), onPressed: () => route.pop()),
        elevation: 0.0,
      ),
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.all(40.w),
        child: Stack(
          children: <Widget>[
            ListView(
              children: <Widget>[
                SizedBox(height: 40.h),
                Center(
                    child: Text(
                  "欢迎登录赶马商城",
                  style: TextStyle(fontSize: 42.s, fontWeight: FontWeight.bold),
                )),
                SizedBox(height: 50.h),
                InkWell(
                  onTap: () {
                    route.pushReplacementNamed(MyRoutes.loginList);
                  },
                  child: Center(
                      child: Container(
                          height: 128.h,
                          width: 128.h,
                          child: Stack(children: <Widget>[
                            LoginIndex.getHeader(),
                            Align(
                                alignment: Alignment.bottomRight,
                                child: Container(
                                  height: 30.h,
                                  width: 30.h,
                                  child: CircleAvatar(
                                      child: Image.asset(
                                          "images/user/ic_sign in_switch.png")),
                                ))
                          ]))),
                ),
                SizedBox(height: 30.h),
                Center(
                    child:
                        Text("${loginMap['def'].replaceRange(3, 7, '****')}")),
                SizedBox(height: 100.h),
                InkWell(
                  onTap: () async {
                    if (loginMap[loginMap['def']]["password"] == "") {
                      route.pushReplacementNamed(MyRoutes.sendCode,
                          arguments: loginMap['def']);
                    } else {
                      bool res = await MemberService().login(loginMap['def'],
                          loginMap[loginMap['def']]["password"]);
                      if (res) {
                        MyToast("登录成功");
                        route.pop();
                      }
                    }
                  },
                  child: Container(
                    height: 80.h,
                    width: 670.w,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(20.h),
                        color: Color(0xFF00C657)),
                    child: Text(
                      "快速登录",
                      style: TextStyle(color: Colors.white, fontSize: 32.s),
                    ),
                  ),
                ),
                SizedBox(height: 50.h),
                InkWell(
                  onTap: () {
                    route.pushReplacementNamed(MyRoutes.codeLogin,
                        arguments: loginMap['def']);
                  },
                  child: Center(
                    child: Text(
                      "切换登录方式",
                      style:
                          TextStyle(color: Color(0xFF333333), fontSize: 24.s),
                    ),
                  ),
                )
              ],
            ),
            Positioned(
                top: 1100.h,
                width: 710.w,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[LoginIndex.xieYi()],
                ))
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
